import request from "@/utils/request";

// 用户相关API
const loginApi = {
	//获取站点配置
	getConfig() {
		return request.get<dataResult>({ url: "/api/customer/guest/getconfig" });
	},
	//获取滑动验证码数据
	getcaptcha() {
		return request.get<dataResult>({ url: "/api/customer/guest/getcaptcha" });
	},
	// 验证码坐标验证
	checkcaptcha(data : CheckCaptchaParams) {
		return request.post<dataResult>({ url: "/api/customer/guest/checkcaptcha", data });
	},
	//短信/邮箱验证码登录--注册---修改密码
	sendcode(data : SendcodeParams) {
		return request.post<dataResult>({ url: "/api/customer/guest/sendcode", data });
	},
	//获得快捷登录
	getoauthurl(data : GetoauthurlParams) {
		return request.post<dataResult>({ url: "/api/customer/guest/getoauthurl", data });
	},
	//快捷登录
	oauthlogin(data : OauthloginParams) {
		return request.post<dataResult>({ url: "/api/customer/guest/oauthlogin", data });
	},
	//会员账号密码注册
	register(data : RegisterParams) {
		return request.post<dataResult>({ url: "/api/customer/guest/register", data });
	},
	// 登录
	login(data : LoginParams) {
		return request.post<dataResult>({ url: "/api/customer/guest/login", data });
	},
	//重置密码
	resetPassword(data : ResetPasswordParams) {
		return request.post<dataResult>({ url: "/api/customer/guest/resetpassword", data });
	}
};

export default loginApi;

interface CheckCaptchaParams {
	key : string;
	answer : string;
}

interface dataResult {
	data ?: any;
	message ?: string;
	status ?: number;
}

// 登录请求参数
interface LoginParams {
	username : string;
	password : string;
	captcha_token : string;
}

//注册请求参数
interface RegisterParams {
	captcha_token : string;
	username : string;
	password : string;
	invite_code ?: string;
}

//重置密码请求参数
interface ResetPasswordParams {
	code : string;
	username : string;
	password : string;
}

interface SendcodeParams {
	captcha_token : string;
	type : string;
	phone ?: string;
	email ?: string;
}

interface GetoauthurlParams {
	redirect_uri : string;
}

interface OauthloginParams {
	type : string;
	code : string;
}